package com.kangyi.user.controller;

import com.kangyi.dto.UserComplaintDTO;
import com.kangyi.result.Result;
import com.kangyi.user.service.UserComplaintService;
import com.kangyi.vo.UserComplaintVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/user/complaint")
@Slf4j
@Api(tags = "意见反馈相关接口")
public class UserComplaintController {

    @Autowired
    private UserComplaintService userComplaintService;


    @PostMapping("/feedback")
    @ApiOperation("意见反馈")
    @CacheEvict( cacheNames = "feedback_",allEntries = true)
    public Result feedback(@RequestBody UserComplaintDTO userComplaintDTO){
        log.info("意见反馈：{}",userComplaintDTO);
        try {
            userComplaintService.feedback(userComplaintDTO);
            return Result.success("反馈成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/inquiry/{userId}")
    @ApiOperation("我的反馈")
    @Cacheable( cacheNames = "feedback_",key = "'userInquiry_'+#userId")
    public Result<List<UserComplaintVO>> inquiryFeedBack(@PathVariable Integer userId){
        log.info("我的反馈:{}",userId);
        try {
            List<UserComplaintVO> userComplaintVOList = userComplaintService.inquiryFeedBack(userId);
            return Result.success(userComplaintVOList,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
